package com.bjsxt.base.sync_shuoGG;

import java.text.SimpleDateFormat;
import java.util.Date;

/*
现象: A线程运行test1期间, B线程无法运行test1, 因为AB线程共用1个NormalUtil对象, 锁一开始被A拿了
输出结果:
    main UseLock NormalUtil.test1 09:13:09
    Thread-0 ThreadNormal2 09:13:09
    main ReleaseLock NormalUtil.test1 09:13:14
    Thread-0 UseLock NormalUtil.test1 09:13:14
    Thread-0 ReleaseLock NormalUtil.test1 09:13:19
*/
public class ThreadNormal2 extends Thread {

    private static NormalUtil normalUtil = new NormalUtil();

    @Override
    public void run() {
        System.out.println(currentThread().getName() + " ThreadNormal2 " + new SimpleDateFormat("HH:mm:ss").format(new Date()));
        normalUtil.test1();
    }

    public static void main(String[] args) {
        new ThreadNormal2().start();
        normalUtil.test1();
    }
}
